/**
 * 项目状态相关的工具函数
 */

export interface ProjectStatus {
  pending: '队列中'
  processing: '处理中'
  completed_generation: '生成完毕'
  partial_failure: '部分失败'
  completed: '已完成'
  failed: '失败'
  cancelled: '已取消'
}

export type ProjectStatusKey = keyof ProjectStatus

/**
 * 获取项目状态文本
 */
export function getProjectStatusText(status: string): string {
  const statusMap: Record<string, string> = {
    pending: '队列中',
    processing: '处理中',
    completed_generation: '生成完毕',
    partial_failure: '部分失败',
    completed: '已完成',
    failed: '失败',
    cancelled: '已取消'
  }
  return statusMap[status] || status
}

/**
 * 获取项目状态类型（用于 Element Plus 标签）
 */
export function getProjectStatusType(status: string): '' | 'success' | 'warning' | 'info' | 'danger' {
  const typeMap: Record<string, '' | 'success' | 'warning' | 'info' | 'danger'> = {
    pending: 'warning',
    processing: '',
    completed_generation: 'success',
    partial_failure: 'warning',
    completed: 'success',
    failed: 'danger',
    cancelled: 'info'
  }
  return typeMap[status]
}

/**
 * 获取状态标签（用于显示）
 */
export function getStatusLabel(status: string): string {
  return getProjectStatusText(status)
}

/**
 * 检查项目是否可以重试
 */
export function canRetryProject(status: string): boolean {
  return ['failed', 'cancelled', 'partial_failure'].includes(status)
}

/**
 * 检查项目是否可以取消
 */
export function canCancelProject(status: string): boolean {
  return ['pending', 'processing'].includes(status)
}